package cn.itcast.weatherapp123.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import cn.itcast.weatherapp123.R;
import cn.itcast.weatherapp123.bean.OtherTipsBean;

public class TipsAdapter extends RecyclerView.Adapter<TipsAdapter.TipsViewHolder> {

    private Context mcontext;
    private List<OtherTipsBean> motherTipsBeanList;

    public TipsAdapter(Context context, List<OtherTipsBean> otherTipsBeanList){

        mcontext=context;
        motherTipsBeanList=otherTipsBeanList;

    }
    @NonNull
    @Override
    public TipsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        View view= LayoutInflater.from(mcontext).inflate(R.layout.tips_item_layout,parent,false);
        TipsViewHolder tipsViewHolder=new TipsViewHolder(view);
        return tipsViewHolder;

    }

    @Override
    public void onBindViewHolder(@NonNull TipsViewHolder holder, int position) {

        OtherTipsBean otherTipsBean=motherTipsBeanList.get(position);

        holder.tvTitle.setText(otherTipsBean.getTitle());
        holder.tvLevel.setText(otherTipsBean.getLevel());
        holder.tvDesc.setText(otherTipsBean.getDesc());

    }

    @Override
    public int getItemCount() {
        if (motherTipsBeanList==null){
            return 0;
        }
        return (motherTipsBeanList==null)?0:motherTipsBeanList.size();

    }



    class TipsViewHolder extends RecyclerView.ViewHolder{

        private TextView tvTitle,tvDesc,tvLevel;

        public TipsViewHolder(@NonNull View itemView) {
            super(itemView);

            tvDesc=itemView.findViewById(R.id.tv_desc);
            tvLevel=itemView.findViewById(R.id.tv_level);
            tvTitle=itemView.findViewById(R.id.tv_title);

        }
    }
}
